<?php
namespace app\demo\service;

use app\demo\model\ExampleCategory as Model;

class Category {

    private $model;

    private static $instance;

    private function __construct() {
        $this->model=new Model();
    }

    public static function instance(){
        if (!self::$instance instanceof self){
            self::$instance = new self();
        }
        return self::$instance;
    }

    public function nodes(){
        static $nodes;
        if($nodes) return $nodes;
        $nodes=$this->model->getOwnRows();
        return $nodes;
    }

    public function options(){
        static $options;
        $options=$options?:[];
        if($options) return $options;
        $nodes=$this->nodes();
        foreach ($nodes as $node) $options[$node["id"]]=$node["name"];
        return $options;
    }

    public function ids(){
        static $ids;
        if($ids) return $ids;
        $ids=array_keys($this->options());
        return $ids;
    }

}